home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / utils / pcxutils / drawstr.asm next >
Assembly Source File  |  1993-07-14  |  9KB  |  224 lines

  1. .model  large
  2. .stack  1024
  3. .386
  4.  
  5. .data
  6. extrn           fontset1:word
  7. message         db      'hey man',0
  8.  
  9. .code
  10.  
  11. _Init_Font              PROC    FAR
  12.                 push    bp
  13.                 mov     bp,sp
  14.  
  15.                 lds     si,dword ptr [bp + 6]
  16.                 mov     cl,byte ptr [si + 3]            ; load # of colors used
  17.                 xor     ch,ch
  18.                 mov     al,byte ptr [si + 4]            ; load starting color
  19.                 xor     ah,ah
  20.                 add     cx,ax                           ; end color =
  21.                 dec     cx                              ; numcolors + start - 1
  22.                 add     si,05h                          ; point to palette
  23.                 push    ds
  24.                 push    si                              ; start of RGB colors
  25.                 push    255
  26.                 push    0
  27.                 call    _Restore_Palette
  28.                 add     sp,8
  29.  
  30.                 pop     bp
  31.                 ret
  32. _Init_Font              ENDP
  33.  
  34. ;******************************************************************************
  35. ; void Draw_String(byte far *fontdata, byte far *string,
  36. ;                  word xcoord, word ycoord, byte page);
  37. ;******************************************************************************
  38. _Draw_String            PROC    FAR
  39.                 push    bp
  40.                 mov     bp,sp
  41.  
  42.                 mov     ax,0a000h
  43.                 mov     es,ax
  44.  
  45.                 lds     si,dword ptr [bp + 6]           ; DS:SI -> fontdata
  46.                 add     si,773                          ; point to offset table
  47.                 mov     dx,[bp + 14]                    ; X coord
  48.  
  49.                 mov     di,[bp + 16]                    ; Y coord
  50.                 shl     di,1                            ; *16
  51.                 shl     di,1
  52.                 shl     di,1
  53.                 shl     di,1
  54.                 mov     bx,di                           ; save
  55.                 shl     di,1                            ; *64
  56.                 shl     di,1
  57.                 add     di,bx                           ; *64 + *16 = *80
  58.  
  59.                 mov     cl,dl                   ; get plane bits from X pos
  60.                 and     cl,00000011b            ; keep in 0-3 range
  61.                 mov     ah,00010001b            ; start at plane 0
  62.                 rol     ah,cl                   ; shift to proper plane
  63.  
  64.                 shr     dx,1                    ; divide X coord by 4
  65.                 shr     dx,1
  66.                 add     di,dx                   ; video offset to start at
  67.                 mov     bl,byte ptr [bp + 18]   ; page
  68.                 and     bx,00003h               ; keep in 0-3 range
  69.                 shl     bx,1                    ; index *2 for word
  70.                 add     di,page_add[bx]         ; final video offset
  71.  
  72.                 lfs     bx,dword ptr [bp + 10]  ; FS:BP -> string
  73.                 mov     bp,bx
  74.                 mov     al,02h                          ; 02h = map mask index
  75.  
  76. setupletter:    xor     bh,bh
  77.                 mov     bl,byte ptr fs:[bp]             ; load letter from message
  78.                 shl     bx,1                            ; *2 = word sized
  79.  
  80.                 mov     cx,word ptr [si + bx]
  81.                 mov     gs,si                           ; save font pointer
  82.                 sub     si,773                          ; back to start
  83.                 add     si,cx                           ; point to proper spot in font file
  84.  
  85.                 mov     ch,byte ptr [si + 1]            ; get X size
  86.                 mov     cl,byte ptr [si + 2]            ; get Y size
  87.                 add     si,03h                          ; point to start of data
  88.  
  89. newplane:       mov     dx,03c4h                        ; sequencer reg
  90.                 out     dx,ax
  91.                 mov     dl,cl                           ; loop Y count
  92.  
  93.                 mov     bx,di                           ; save video pointer
  94. drawcolumn:     mov     dh,byte ptr [si]                ; draw a column
  95.                 mov     es:[di],dh
  96.                 inc     si                              ; next byte in column
  97.                 add     di,80                           ; next video line
  98.                 dec     dl                              ; decrement height
  99.                 jnz     drawcolumn
  100.                 mov     di,bx                           ; restore video pointer
  101.  
  102.                 rol     ah,1
  103.                 adc     di,0
  104.                 dec     ch
  105.                 jnz     newplane
  106.  
  107. nextletter:     mov     si,gs
  108.                 inc     bp                              ; next letter in message
  109.                 cmp     byte ptr fs:[bp],00h
  110.                 jne     setupletter
  111.  
  112.                         pop     bp
  113.                         ret
  114. _Draw_String            ENDP
  115.  
  116. ;******************************************************************************
  117. ; void Draw_Char(byte far *fontdata, byte far *string,
  118. ;                word xcoord, word ycoord, byte page);
  119. ;******************************************************************************
  120. _Draw_Char              PROC    FAR
  121.                 push    bp
  122.                 mov     bp,sp
  123.  
  124.                 mov     ax,0a000h
  125.                 mov     es,ax
  126.  
  127.                 lds     si,dword ptr [bp + 6]           ; DS:SI -> fontdata
  128.                 add     si,773                          ; point to offset table
  129.                 mov     dx,[bp + 14]                    ; X coord
  130.  
  131.                 mov     di,[bp + 16]                    ; Y coord
  132.                 shl     di,1                            ; *16
  133.                 shl     di,1
  134.                 shl     di,1
  135.                 shl     di,1
  136.                 mov     bx,di                           ; save
  137.                 shl     di,1                            ; *64
  138.                 shl     di,1
  139.                 add     di,bx                           ; *64 + *16 = *80
  140.  
  141.                 mov     cl,dl                   ; get plane bits from X pos
  142.                 and     cl,00000011b            ; keep in 0-3 range
  143.                 mov     ah,00010001b            ; start at plane 0
  144.                 rol     ah,cl                   ; shift to proper plane
  145.  
  146.                 shr     dx,1                    ; divide X coord by 4
  147.                 shr     dx,1
  148.                 add     di,dx                   ; video offset to start at
  149.                 mov     bl,byte ptr [bp + 18]   ; page
  150.                 and     bx,00003h               ; keep in 0-3 range
  151.                 shl     bx,1                    ; index *2 for word
  152.                 add     di,page_add[bx]         ; final video offset
  153.  
  154.                 lfs     bx,dword ptr [bp + 10]  ; FS:BP -> string
  155.                 mov     bp,bx
  156.                 mov     al,02h                          ; 02h = map mask index
  157.  
  158. setupletter1:   xor     bh,bh
  159.                 mov     bl,byte ptr fs:[bp]             ; load letter from message
  160.                 shl     bx,1                            ; *2 = word sized
  161.  
  162.                 mov     cx,word ptr [si + bx]
  163.                 mov     gs,si                           ; save font pointer
  164.                 sub     si,773                          ; back to start
  165.                 add     si,cx                           ; point to proper spot in font file
  166.  
  167.                 mov     ch,byte ptr [si + 1]            ; get X size
  168.                 mov     cl,byte ptr [si + 2]            ; get Y size
  169.                 add     si,03h                          ; point to start of data
  170.  
  171. newplane1:      mov     dx,03c4h                        ; sequencer reg
  172.                 out     dx,ax
  173.                 mov     dl,cl                           ; loop Y count
  174.  
  175.                 mov     bx,di                           ; save video pointer
  176. drawcolumn1:    mov     dh,byte ptr [si]                ; draw a column
  177.                 mov     es:[di],dh
  178.                 inc     si                              ; next byte in column
  179.                 add     di,80                           ; next video line
  180.                 dec     dl                              ; decrement height
  181.                 jnz     drawcolumn1
  182.                 mov     di,bx                           ; restore video pointer
  183.  
  184.                 rol     ah,1
  185.                 adc     di,0
  186.                 dec     ch
  187.                 jnz     newplane1
  188.  
  189.                         pop     bp
  190.                         ret
  191. _Draw_Char              ENDP
  192.  
  193. start:          mov     ax,@data
  194.                 mov     ds,ax
  195.  
  196. ; Initialize 320x200x256 tweaked mode
  197.                 push    0
  198.                 call    _Init_Tweaked_Mode
  199.                 add     sp,2
  200.  
  201.                 push    ds
  202.                 push    offset fontset1
  203.                 call    _Init_Font
  204.                 add     sp,4
  205.  
  206.                 push    0
  207.                 push    80
  208.                 push    65
  209.                 push    ds
  210.                 push    offset message
  211.                 push    ds
  212.                 push    offset fontset1
  213.                 call    _Draw_String
  214.                 add     sp,14
  215.  
  216.                 call    _Wait_Key
  217.  
  218.                 mov     ax,0003h
  219.                 int     10h
  220.                 mov     ax,4c00h
  221.                 int     21h
  222.  
  223.                 end     start
  224.